home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / CH6 / EMAGA6 / control / client / misc / serverscreen.cs < prev    next >
Text File  |  2006-06-22  |  3KB  |  116 lines

  1. //============================================================================
  2. // control/client/misc/ServerScreen.cs
  3. //
  4. // Server query code module for 3D2E emaga6 sample game
  5. //
  6. // Copyright (c) 2003 by Kenneth C.  Finney.
  7. //============================================================================
  8.  
  9. //----------------------------------------
  10. function ServerScreen::onWake()
  11. {
  12.    // Double check the status. Tried setting this the control
  13.    // inactive to start with, but that didn't seem to work.
  14.    JoinServer.SetActive(ServerList.rowCount() > 0);
  15.    ServerScreen.queryLan();
  16. }
  17.  
  18. //----------------------------------------
  19. function ServerScreen::queryLan(%this)
  20. {
  21.    queryLANServers(
  22.       28000,      // lanPort for local queries
  23.       0,          // Query flags
  24.       $Client::GameTypeQuery,       // gameTypes
  25.       $Client::MissionTypeQuery,    // missionType
  26.       0,          // minPlayers
  27.       100,        // maxPlayers
  28.       0,          // maxBots
  29.       2,          // regionMask
  30.       0,          // maxPing
  31.       100,        // minCPU
  32.       0           // filterFlags
  33.       );
  34. }
  35.  
  36.  
  37. //----------------------------------------
  38. function ServerScreen::Cancel(%this)
  39. {
  40.    CancelServerQuery();
  41. }
  42.  
  43.  
  44. //----------------------------------------
  45. function ServerScreen::Join(%this)
  46. {
  47.    CancelServerQuery();
  48.    %id = ServerList.GetSelectedId();
  49.  
  50.    // The server info index is stored in the row along with the
  51.    // rest of displayed info.
  52.    %index = getField(ServerList.GetRowTextById(%id),6);
  53.    if (SetServerInfo(%index)) {
  54.       %conn = new GameConnection(ServerConnection);
  55.       %conn.SetConnectArgs($pref::Player::Name);
  56.       %conn.SetJoinPassword($Client::Password);
  57.       %conn.Connect($ServerInfo::Address);
  58.    }
  59. }
  60.  
  61. //----------------------------------------
  62. function ServerScreen::Close(%this)
  63. {
  64.    cancelServerQuery();
  65.    Canvas.SetContent(MenuScreen);
  66. }
  67.  
  68. //----------------------------------------
  69. function ServerScreen::Update(%this)
  70. {
  71.    // Copy the servers into the server list.
  72.    QueryStatus.SetVisible(false);
  73.    ServerList.Clear();
  74.    %sc = getServerCount();
  75.    for (%i = 0; %i < %sc; %i++) {
  76.       setServerInfo(%i);
  77.       ServerList.AddRow(%i,
  78.          ($ServerInfo::Password? "Yes": "No") TAB
  79.          $ServerInfo::Name TAB
  80.          $ServerInfo::Ping TAB
  81.          $ServerInfo::PlayerCount @ "/" @ $ServerInfo::MaxPlayers TAB
  82.          $ServerInfo::Version TAB
  83.          $ServerInfo::GameType TAB
  84.          %i);  // ServerInfo index stored also
  85.    }
  86.    ServerList.Sort(0);
  87.    ServerList.SetSelectedRow(0);
  88.    ServerList.scrollVisible(0);
  89.  
  90.    JoinServer.SetActive(ServerList.rowCount() > 0);
  91. }
  92.  
  93. //----------------------------------------
  94. function onServerQueryStatus(%status, %msg, %value)
  95. {
  96.    // Update query status
  97.    // States: start, update, ping, query, done
  98.    // value = % (0-1) done for ping and query states
  99.    if (!QueryStatus.IsVisible())
  100.       QueryStatus.SetVisible(true);
  101.  
  102.    switch$ (%status) {
  103.       case "start":
  104.  
  105.       case "ping":
  106.          StatusText.SetText("Finding Hosts");
  107.          StatusBar.SetValue(%value);
  108.  
  109.       case "query":
  110.  
  111.       case "done":
  112.          QueryStatus.SetVisible(false);
  113.          ServerScreen.update();
  114.    }
  115. }
  116.